﻿
Imports managedServer
Imports webctrl

Public Module urlshortenmain

    Public Const defaultConfigfile As String = "urlshorten.ini"
    Public recordCount As Int64 = 0

    Public Function usclientDownloadLink() As String
        Return staticrequest.generateStaticfileLinkUrl("usclient.zip")
    End Function

    Public Function wmusclntDownloadLink() As String
        Return staticrequest.generateStaticfileLinkUrl("wmusclnt.zip")
    End Function

    Public Function generateSnapshotLink(ByVal baselink As String, ByVal desturl As String) As String
        Return baselink + urlUtils.urlencode(desturl)
    End Function

    Public Function generateIe8AcceleratorInstallerInfo() As ie8acceleratorInstallerInfo
        Dim info As ie8acceleratorInstallerInfo = Nothing
        info = New ie8acceleratorInstallerInfo()
        info.name = "urlshorten service"
        info.desctiption = "can give you a short url and write to clipboard"
        info.acc = strmid(ie8acc._pathidentity, strlen(network.pathSeperator))
#If RETIRED Then
        info.filename = "usacc.xml"
#End If
        info.acc = strmid(ie8acc._pathidentity, strlen(network.pathSeperator))
        info.category = "urlshorten"

        Return info
    End Function

    Public Function generateIe8AcceleratorAction(ByVal context As String, _
                                                 ByVal link As String) As ie8acceleratorInfo.action
        Dim rtn As ie8acceleratorInfo.action = Nothing
        rtn = New ie8acceleratorInfo.action()
        rtn.context = context

        Dim execute As ie8acceleratorInfo.execute = Nothing
        execute = New ie8acceleratorInfo.execute()
        execute.method = "get"
        execute.actionPath = emptyString

        Dim parameter As ie8acceleratorInfo.parameter = Nothing
        parameter = New ie8acceleratorInfo.parameter()
        parameter.name = usshare.query.url
        parameter.value = link
        parameter.type = ie8acceleratorInfo.parameter.text
        execute.parameters.push_back(parameter)

        parameter = New ie8acceleratorInfo.parameter()
        parameter.name = usshare.query.action
        parameter.value = usshare.actionVerbs(usshare.action.submit)
        execute.parameters.push_back(parameter)

        parameter = New ie8acceleratorInfo.parameter()
        parameter.name = "src"
        parameter.value = "ie8acc"
        execute.parameters.push_back(parameter)

        rtn.executes.push_back(execute)
        Return rtn
    End Function

    Public Function generateIe8AcceleratorInfo() As ie8acceleratorInfo
        Dim info As ie8acceleratorInfo = Nothing
        info = New ie8acceleratorInfo()
        info.name = "urlshorten [Hzj_jie]"
        info.icon = "favicon.ico"
        info.description = "urlshorten service from Hzj_jie"

        Dim activity As ie8acceleratorInfo.activity = Nothing
        activity = New ie8acceleratorInfo.activity()
        activity.category = "urlshorten"
        activity.actions.push_back(generateIe8AcceleratorAction(ie8acceleratorInfo.action.document, _
                                                                ie8acceleratorInfo.parameter.documentUrl))
        activity.actions.push_back(generateIe8AcceleratorAction(ie8acceleratorInfo.action.link, _
                                                                ie8acceleratorInfo.parameter.link))
        activity.actions.push_back(generateIe8AcceleratorAction(ie8acceleratorInfo.action.selection, _
                                                                ie8acceleratorInfo.parameter.documentUrl))
        info.activities.push_back(activity)
        Return info
    End Function

    Public Sub main(ByVal args() As String)
        loosenSPMLimit(1024)
        ProHttpS.managedRequestProcessors().insert(New ie8accInstaller(generateIe8AcceleratorInstallerInfo()))
        ProHttpS.managedRequestProcessors().insert(New ie8acc(generateIe8AcceleratorInfo()))
        ProHttpS.managedRequestProcessors().insert(New usclient())
        ProHttpS.managedRequestProcessors().insert(New wmusclnt())
        ProHttpS.managedRequestProcessors().insert(New idcard())
        ProHttpS.managedRequestProcessors().insert(New xmlapi())
        ProHttpS.managedRequestProcessors().insert(New xmlapi2())
        ProHttpS.managedRequestProcessors().insert(New txtapi())
        ProHttpS.managedRequestProcessors().insert(New urlshorten())
        ProHttpS.defaultConfigfile = defaultConfigfile
        ProHttpS.startServer(args, configNaming.urlshorten.name, New httpContext.parameterDefinition(stringsPackage:=sp))
    End Sub
End Module
